/*
 * main.cpp
 *
 *  Created on: Mar 8, 2010
 *      Author: Vu Phuong Hoang
 */

#include <iostream>
#include <assert.h>
#include <math.h>

#include "Allocation.h"
#include "TerrainMap.h"
#include "PathFinder.h"
#include "AStar.h"

using namespace std;

float getDistance(Coordinate a, Coordinate b) {
	return sqrt( (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) );
}

float getWeight(float t) {
	return t;
}

int main() {
	float **x;
	//Test Allocation.h
	bool ok = newMatrix( x, 3, 3, (float) 0 );
	cout << ok << endl;
	assert(ok);

	//Test TerrainMap.h
	x[0][0] = 9;
	TerrainMap<float> m( 3, 3, x );
	assert(m.isMapAvailable());
	for (unsigned int i = 0; i < m.getRows(); ++i) {
		for (unsigned int j = 0; j < m.getColumns(); ++j) {
			printf( "%3f ", m.get( i, j ) );
		}
		cout << endl;
	}
	cout << "Element that is out of boundary will be assumed that it has value equal to first element ("
			<< m.get( 4, 4 ) << ")";
	assert(m.get(4, 4) == m.get(0, 0));

	//Test Coordinate.h
	/*Coordinate a( 2, 8 );
	 Coordinate *b = new Coordinate( 5, 2 );
	 cout << a.x << ", " << a.y << endl;
	 cout << b->x << ", " << b->y << endl;
	 cout << (a==*b ? 1 : 0) << endl;*/

	//Test PathFinder.h
	AStar<float> *pkEngine = new AStar<float> ( m, getDistance, getWeight );
	cout << endl << pkEngine->getMap().get( 0, 0 ) << endl;
	cout << endl << pkEngine->pfGetWeight( pkEngine->getMap().get( 0, 1 ) );

	cout << "\nFinish!";
	fflush( stdin );
	//cin.get();
	return 0;
}
